<template>
  <div class="shop shopManage">
    <div class="basicBody">
      <div v-if="websiteName == 1">
        <mt-field  placeholder="输入店铺名称" type="text" v-model="portalWebsiteData.websiteName"></mt-field>
      </div>
      <div v-if="websiteRemark == 2">
        <mt-field  placeholder="输入店铺介绍" type="text" v-model="portalWebsiteData.websiteRemark"></mt-field>
      </div>
      <div v-if="memberName == 3">
        <mt-field  placeholder="输入联系人" type="text" v-model="portalWebsiteData.memberName"></mt-field>
      </div>
      <div v-if="operatorPhone == 4">
        <mt-field  placeholder="输入手机号" type="text" v-model="portalWebsiteData.operatorPhone"></mt-field>
      </div>
    </div>
    <button :disabled="but_disabled" :class="{gray:but_disabled}" class="save_btn" @click="portal_website_update">保存</button>

  </div>
</template>
<script>
  import { Toast } from 'mint-ui'; //引入弹框
  export default{
    data(){
      return{
        memberCode: "",	//分销商编号
        //初始化页面数据
        portalWebsiteData: {
          websiteName:"",
          websiteRemark:"",
          memberName:"",
          operatorPhone:"",
        },
        websiteName:"",    //根据路由判断修改（店铺名称）
        websiteRemark:"",    //根据路由判断修改（店铺介绍）
        memberName:"",     //根据路由判断修改（联系人）
        operatorPhone:"",     //根据路由判断修改（手机号）
        but_disabled:false,   //按钮禁用
      }
    },
    methods:{
      //页面保存按钮
      portal_website_update(){
         if(this.operatorPhone == 4){
           if(!/^(13[0-9]|14[57]|15[012356789]|17[67]|18[012356789])\d{8}$/.test(this.portalWebsiteData.operatorPhone)){
             Toast({
               message: '手机号格式错误！',
             });
             return false
           }
         }
        this.but_disabled = true;
        this.axios({
          method: 'PUT',
          url: "/v3/portal/websites/" + localStorage.getItem("websiteCode") + "/updateByAgentAccount",
          data: {
            "websiteName": this.portalWebsiteData.websiteName,	//网站名称
            "websiteRemark": this.portalWebsiteData.websiteRemark,	//网站说明
            "memberName": this.portalWebsiteData.memberName,	//联系人
            "operatorPhone": this.portalWebsiteData.operatorPhone	//手机号
          },
        }).then((res) => {
          this.but_disabled = false;
          this.$router.push({path:"/shopManage"});
          Toast({
            message: '保存成功！',
            iconClass: 'fontSize iconfont icon-chenggong'
          });
        }).catch((err)=>{
          this.but_disabled = false;
          Toast({
            message: err.response.data,
            iconClass: 'fontSize iconfont icon-shibai'
          });
        });

      },

      //初始化店铺数据
      portal_website_queryDataByMemberCode(){
        this.axios({
          method: 'GET',
          url: "/v3/portal/websites/" + localStorage.getItem("memberCode") + "/queryDataByMemberCode",
          data: {},
        }).then((res) => {
          this.portalWebsiteData = res.data;
        }).catch((err)=>{
          Toast({
            message: err.response.data,
            iconClass: 'fontSize iconfont icon-shibai'
          });
        });
      },

    },

    activated(){
      //存储路由信息
      this.websiteName = this.$route.query.websiteName;
      this.websiteRemark = this.$route.query.websiteRemark;
      this.memberName = this.$route.query.memberName;
      this.operatorPhone = this.$route.query.operatorPhone;
      this.portal_website_queryDataByMemberCode();    //（显示默认）数据
      document.querySelector('#vue_id_title').innerHTML="修改店铺信息";
    },

  }
</script>
<style scoped>

  .gray{
    background: #999999!important;
  }

  h4{
    font-style: normal;
    font-weight: normal;
  }

  .save_btn{
    width: 96%;
    background:#D50B0A;
    color: white;
    display: block;
    margin: 20px auto;
    text-align: center;
    height: 1rem;
    line-height: 1rem;
    border-radius: 4px;
    border: none;
  }

  .shopManage{
    min-height: 17.75rem;
    overflow: hidden;
  }

  .basicBody{
    margin-top: .3rem;
    background: #fff;
    overflow: hidden;
  }

</style>
